package utils

import (
	"servers/models/define"
	"servers/models/meta"
)

func GetTotalRtp(info *meta.RptInfo) define.RTPValue {
	if info.TotalIn == 0 {
		return define.RTPBase
	}
	return define.RTPValue(float64(info.TotalOut) / float64(info.TotalIn) * define.RTPBase)
}

func CheckRestoreTotalRtp(info *meta.RptInfo, rtp define.RTPValue) define.GameScore {
	if info.TotalIn == 0 {
		return 0
	}
	out := define.GameScore(float64(rtp) / define.RTPBase * float64(info.TotalIn))
	if out < info.TotalOut {
		return 0
	}
	return out - info.TotalOut
}

func GetDailyRtp(info *meta.RptInfo) define.RTPValue {
	if info.DailyIn == 0 {
		return define.RTPBase
	}
	return define.RTPValue(float64(info.DailyOut) / float64(info.DailyIn) * define.RTPBase)
}

func CheckRestoreDailyRtp(info *meta.RptInfo, rtp define.RTPValue) define.GameScore {
	if info.DailyIn == 0 {
		return 0
	}
	out := rtp * info.DailyIn / define.RTPBase
	if out < info.DailyOut {
		return 0
	}
	return out - info.DailyOut
}

func GetRoundRtp(info *meta.RptInfo) define.RTPValue {
	if info.RoundIn == 0 {
		return define.RTPBase
	}
	return define.RTPValue(float64(info.RoundOut) / float64(info.RoundIn) * define.RTPBase)
}

func CheckRestoreRoundRtp(info *meta.RptInfo, rtp define.RTPValue) define.GameScore {
	if info.RoundIn == 0 {
		return 0
	}
	out := rtp * info.RoundIn / define.RTPBase
	if out < info.RoundOut {
		return 0
	}
	return out - info.RoundOut
}
